package edu.cis084.week5;

import java.util.Scanner;

public class DoTempConv 
{

	public static void main(String[] args) 
	{
		float tempVal;
		boolean loopProg=true;
		TemperatureConverter temp1 = new TemperatureConverter();
		TemperatureConverter temp2 = new TemperatureConverter();
		String curScale, convScale, endProg;
		Scanner userInputStream = new Scanner(System.in);
		
		do
		{
			try
			{
				System.out.print("Enter the number of degrees for the first temperature: ");
				tempVal = userInputStream.nextInt();
				temp1.setTemperatureValue(tempVal);
				System.out.print("Enter the scale for the first temperature (c,f,k): ");
				curScale = userInputStream.next();
				temp1.setTemperatureScale(curScale); //Throws an InvalidScaleException if input is bad.
				System.out.print("Enter the number of degrees for the second temperature: ");
				tempVal = userInputStream.nextInt();
				temp2.setTemperatureValue(tempVal);
				System.out.print("Enter the scale for the second temperature(c,f,k): ");
				curScale = userInputStream.next();
				temp2.setTemperatureScale(curScale); //Throws an InvalidScaleException if input is bad.
				System.out.print("Enter the scale to convert the first temperature to (c,f,k): ");
				convScale = userInputStream.next();
				
				if(temp1.equals(temp2))
					System.out.println("Temp 1 equals Temp 2.");
				else if (temp1.lessThan(temp2))
					System.out.println("Temp 1 less than Temp 2.");
				else if (temp1.greaterThan(temp2))
					System.out.println("Temp 1 greater than Temp 2.");
				
				System.out.println(temp1.toString() + " converts to " + temp1.convertTo(convScale) + convScale + "."); //Throws an InvalidScaleException if input is bad.
			}
			catch(InvalidScaleException e)
			{
				System.out.println("Invalid temperature scale entered.");
			}
						
			System.out.print("Do another calculation? (y/n): ");
			endProg=userInputStream.next();
			if(endProg.equalsIgnoreCase("n"))
				loopProg=false;
		}
		while(loopProg==true);
		
		//Test the overloaded constructor's functionality.
		
		/*TemperatureConverter temp2 = new TemperatureConverter(100, "F", "C");
		System.out.println("Before conversion, I think temp2 looks like this: " + temp2);
		System.out.println(temp2.convert());*/
		System.out.println("Quitting.");
		userInputStream.close();
	}

}
